package com.itheima.controller;

import com.itheima.common.Com.AddressBook;
import com.itheima.common.pojo.Result;
import com.itheima.common.vo.AddressBookDto;
import com.itheima.common.vo.AddressBookVo;
import com.itheima.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/addressBook")
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;

    @GetMapping("/list")
    public Result list(){
        List<AddressBook> list = addressBookService.list();
        return Result.success("成功",list);
    }
    @PostMapping()
    public Result add(@RequestBody AddressBookVo addressBookVo){
        AddressBookVo add = addressBookService.add(addressBookVo);
        return Result.success("",add);
    }
    @GetMapping("{id}")
    public Result getById(@PathVariable("id") String id){
        AddressBook byid = addressBookService.getByid(id);
        return Result.success(byid);
    }
    @GetMapping("/default")
    public Result getmoren(){
        AddressBook getmoren = addressBookService.getmoren();
        return Result.success(getmoren);
    }
    @PutMapping("/default")
    public Result updateMoren(@RequestBody AddressBookDto addressBookDto){
        boolean b = addressBookService.updateMoren(addressBookDto);
        return Result.success(b);
    }
    @PutMapping
    public Result updateById(@RequestBody AddressBook addressBook){
        boolean b = addressBookService.updateById(addressBook);
        return Result.success("",b);
    }
    @DeleteMapping
    public Result delete(@RequestParam("ids") String ids){

        boolean delete = addressBookService.delete(ids);
        return Result.success("",delete);
    }
}
